package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
//
@RestController
@Api(tags = "检查组管理开发")
public class CheckGroupController {

    // springmvc  消息转化器   @ResponseBody  默认 全字段序列化

    @Reference
    private CheckGroupService checkGroupService;

    @GetMapping("checkgroup/findAll")
    @ApiOperation(value = "查询功能",notes = "查询所有的检查组列表信息")
    public Result findAll(){



        return new Result(checkGroupService.list());
    }
    @GetMapping("checkgroup/findCheckIteminfosByGroupId/{id}")
    @ApiOperation(value = "查询功能",notes = "根据检查组id查询对应检查项明细")
    public Result findCheckIteminfosByGroupId(@PathVariable("id") int id){
        return new Result(checkGroupService.findCheckIteminfosByGroupId(id));
    }

    @PostMapping("checkgroup/findPage")
    @ApiOperation(value = "分页查询功能",notes = "查询所有的检查组列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //    分页查询  条件  页码  记录数  条件
        //  集合 插件  PageResult对象
        return new Result(checkGroupService.findPage(queryPageBean));
    }
//
//    @DeleteMapping("checkitem/deleteCheckItemById/{id}")
//    @ApiOperation(value = "分页查询功能",notes = "查询所有的检查项列表信息")
//    public Result deleteCheckItemById(@PathVariable("id") int id){
//        CheckItem checkItem = new CheckItem();
//        checkItem.setId(id);
//        checkItem.setIs_delete(1);  //  update .... set  is_delete = 1 where id = ?
//         return  new Result(checkItemService.updateById(checkItem));
//    }

    @PostMapping("checkgroup/saveOrUpdate")
    @ApiOperation(value = "添加功能",notes = "添加检查组")
    public Result  saveOrUpdate(@RequestBody CheckGroupDTO checkGroupDTO ){
        return  new Result(checkGroupService.saveUpdate(checkGroupDTO));

    }
}
